Explain about DML trigger with an example.
Explain about DML trigger with an example.
413
22-Mar-2023
Updated on 30-Mar-2023
Krishnapriya Rajeev
30-Mar-2023Data Manipulation Language (DML) triggers are fired in response to events caused by DML statements like INSERT, UPDATE, and DELETE. They can also be triggered by system-defined stored procedures that perform operations similar to DML statements. These triggers can be used to ensure data integrity and also to query other tables.
There are two types of DML triggers:
a. AFTER Trigger
It is fired when the SQL server action that triggered it is completed. It is typically executed whenever an INSERT, UPDATE, or DELETE operation on a table is completed.
Example:
b. INSTEAD OF Trigger
It is fired before the SQL server begins executing the action that triggers it. Hence, the trigger will fire even if the constraint check fails.
Example: